import {defineStore} from 'pinia'
import {ref, computed} from 'vue'

export interface routerHistoryType {
  name: string,
  meta?: string,
  promptCode: string
  promptTitle: string
  params: { username: string }
}

export const useStore = defineStore('addRouter', () => {
  let routerHistory = ref<routerHistoryType[]>([])
  let isCreateHistory = ref<boolean>(false)
  let isHistory = ref<boolean>(true)
  let isAddRouter = ref<boolean>(true)
  let promptCode = ref<string>('')
  let promptName = ref<string>('')
  const addHistoryRouter = (router: routerHistoryType) => {
    routerHistory.value.unshift(router)
  }
  const deleteHistoryRouter = (deleteIndex: number) => {
    routerHistory.value.splice(deleteIndex, 1)
  }
  const clearHistoryRouter = () => {
    routerHistory.value = []
  }

  const changeIsCreateHistory = (isChange: boolean) => {
    isCreateHistory.value = isChange
  }
  const changeIsHistory = (isChange: boolean) => {
    isHistory.value = isChange
  }

  const changePromptCode = (code: string) => {
    promptCode.value = code
  }
  const changePromptName = (name: string) => {
    promptName.value = name
  }
  const changeIsAddRouter = (isChange: boolean) => {
    isAddRouter.value = isChange
  }
  return {
    routerHistory,
    isHistory,
    promptCode,
    promptName,
    isAddRouter,
    addHistoryRouter,
    changeIsHistory,
    changePromptCode,
    changePromptName,
    changeIsAddRouter,
    deleteHistoryRouter,
    clearHistoryRouter
  }
})